package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;


@Getter
@Setter
public class Region extends BaseDomain {
    public static final int STATE_COMMON = 0; //普通
    public static final int STATE_DISABLED = -1; //禁用
    public static final int STATE_HOT = 1; //推荐
    //名称
    private String name;
    //上级地区
    private Region parent;
    //状态
    private int state;

    public Map toTreeViewMap() {
        HashMap<Object, Object> map = new HashMap();
        map.put("id", id);
        map.put("text", name);
        map.put("lazyLoad", true);
        if (state == STATE_HOT) {
            map.put("tags", new String[]{"推荐"});
        }
        return map;
    }

    public String getJsonString() {
        HashMap<Object, Object> map = new HashMap();
        map.put("id", id);
        map.put("name", name);
        map.put("state", state);
        if (parent != null) {
            map.put("parentId", parent.getId());
            map.put("parentName", parent.getName());
        }
        return JSON.toJSONString(map);
    }
}